
(function ( $ ) {
	$.log = {
		  logLevel:2
		, logError:0
		, logInfo:1
		, logDebug:2
		, setLevel:function(pLevel){
			if( pLevel == 'debug' ){
				this.logLevel = this.logDebug;
			}else if( pLevel == 'info' ){
				this.logLevel = this.logInfo;
			}else{
				this.logLevel = this.logError;
			}
		}
		, consolePrint: function(msg, pCurLevel){
			if (window.console){
				var curDate = new Date();
				console.log( ''
					+ pCurLevel
					+ ' - ' 
					+ curDate.getMinutes()
					+ ':'
					+ curDate.getMilliseconds()
					+ '['
					+ msg 
					+ ']'
				);
			}
		}
		, error: function(msg){
			if (this.logLevel >= this.logError){
				this.consolePrint( msg, 'error' );
			}
		}
		, info: function(msg){
			if (this.logLevel >= this.logInfo){
				this.consolePrint( msg, 'info' );
			}
		}
		, debug: function(msg){
			if (this.logLevel >= this.logDebug ){
				this.consolePrint( msg, 'debug' );
			}
		}
	};
	
	$.fn.logToggle = function(options) {
		$(this).bind({
			keypress : function ( e ){
				$.log.debug( 'press[' + e.keyCode + ']' );
				if( e.keyCode == 68 ){//'D'
					$.log.setLevel( 'debug' );
				}else if( e.keyCode == 73 ){//'I'
					$.log.setLevel( 'info' );
				}else if( e.keyCode == 69 ){//'E'
					$.log.setLevel( 'error' );
				}
			}
		});
		return this.each(function(){$this = $(this);});
	};
	
})(jQuery);

